#ifndef FFMPEG_CAMERA_H
#define FFMPEG_CAMERA_H

#include <string>
#ifdef _WIN32
#include <Windows.h>
#endif
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include <log4cxx/logger.h>
#include "CameraBase.h"

#ifdef DLL_EXPORT
class _declspec(dllexport) FFmpegCamera : public CameraBase
#else
class FFmpegCamera : public CameraBase
#endif
{
public:
    FFmpegCamera();
    ~FFmpegCamera();
    int Init(HWND hwnd, const char *path, bool device = false);
    void SetCallback(VideoDataCallback callback, void *context);
    int Connect();
    int Disconnect();

    VideoDataCallback callback;
    void *context;
    bool hardwareRender = true;
    bool device = false;

private:
    bool InitLibrary();
    bool UninitLibrary();
#ifdef _WIN32
    LONGLONG GetCurrentTime();
    static DWORD WINAPI DecodeThread(LPVOID lpParam);
    static DWORD WINAPI ReconnectThread(LPVOID lpParam);
#else
    static void* DecodeThread(void* arg);
#endif
    static int DecodeInterruptCallback(void *context);

    HWND hwnd;
    bool running;
#ifdef _WIN32
    bool reconnect;
    HANDLE hDecodeThread;
    HANDLE hReconnectThread;
    HANDLE hEvent;
    LONGLONG prevTime;
#endif
    std::string path;
    log4cxx::LoggerPtr logger;
};

#endif
